#!/usr/bin/env sh

. ${HOME}/.config/scripts/color/i3blocks-cap-color.sh

BATTERY="/sys/class/power_supply/BATT"
BATTERY_CAP=$(cat "${BATTERY}/capacity")
BATTERY_STATUS=$(cat "${BATTERY}/status")

BATTERY_COLOR=${HIGH_CAP_COLOR}

case "${BATTERY_STATUS}" in
    "Discharging")
        case "${BATTERY_CAP}" in
            [0-9]) ICON="\Uf008e" BATTERY_COLOR=${VERY_LOW_CAP_COLOR};;
            1[0-9]) ICON="\Uf007a" BATTERY_COLOR=${LOW_CAP_COLOR};;
            2[0-9]) ICON="\Uf007b" BATTERY_COLOR=${LOW_CAP_COLOR};;
            3[0-9]) ICON="\Uf007c" BATTERY_COLOR=${MIDDLE_CAP_COLOR};;
            4[0-9]) ICON="\Uf007d" BATTERY_COLOR=${MIDDLE_CAP_COLOR};;
            5[0-9]) ICON="\Uf007e" BATTERY_COLOR=${MIDDLE_CAP_COLOR};;
            6[0-9]) ICON="\Uf007f";;
            7[0-9]) ICON="\Uf0080";;
            8[0-9]) ICON="\Uf0081";;
            9[0-9]) ICON="\Uf0082";;
            100)    ICON="\Uf0079";;
        esac
        ;;
    "Not charging")
        ICON="\Uf1e6"
        ;;
    "Charging")
        ICON="\Uf0084"
        ;;
    "Full")
        ICON="\Uf0079"
        ;;
esac

echo -e "${ICON} ${BATTERY_CAP}%\n\n${BATTERY_COLOR}"
